function Workspace(name)
{
	var _containers;
	var _name;
	var _id;

	this.getName = function() {
		return _name;
	}
	this.getAllContainers = function() {
		return _containers;
	}
	this.getId = function() {
		return _id;
	}
    
	function _construct(name)
	{
		_name = name;
		_containers = [];
		_id = Workspace.instances.length+1;
	}

	this.addContainer = function(scontainer)
	{
		if (!(scontainer instanceof SearchContainer))
			this.sendError("Le conteneur ajouté n'est pas de type SearchContainer");

		_containers.push(scontainer);
	}

	this.removeContainer = function(container)
	{
		var founded = false;
		for (var i = 0; i < _containers.length; i++)
		{
			if (container == _containers[i])
			{
				_containers.splice(i,1);
				founded = true;
				break;
			}
		}
		if (!founded)
			container.remove();
	}

	_construct(name);
}

Workspace.getById = function(id)
{
	var elem = null;
	for (var i = 0; i < Workspace.instances.length; i++)
	{
		if (Workspace.instances[i].getId() == id)
		{
			elem = Workspace.instances[i];
			break;
		}
	}

	return elem;
}

Workspace.instances = [];

Workspace.createWorkspace = function(name)
{
	var work = new Workspace(name);
	Workspace.instances.push(work);

	return work;
}

Workspace.deleteWorkspace = function(id)
{
	for (var i = 0; i < Workspace.instances.length; i++)
	{
		if (Workspace.instances[i].getId() == id)
		{
			Workspace.instances.splice(i,1);
			break;
		}
	}
}

Workspace.sortByName = function(w1,w2)
{
	if (w1.getName() == w2.getName())
		return 0;
	else if (w1.getName() > w2.getName())
		return 1;
	else
		return -1;
}


Workspace.$useError();